<template>
  <div>
    <div class="an">
      <div class="ming">
        <button style="background-color: #11c43c">添加</button>
        <button style="background-color: red" >删除</button>
      </div>
    </div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="50"></el-table-column>
      <el-table-column label="日期" width="200">
            <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="150"> </el-table-column>
      <el-table-column prop="value" label="金额" sortable width="150">
      </el-table-column>
      <el-table-column prop="address" label="支出用途" width="500" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除
            </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 1000,
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 2000,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 9999,
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 1234,
        },
        {
          date: "2016-05-08",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 1999,
        },
        {
          date: "2016-05-06",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 10000,
        },
        {
          date: "2016-05-07",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 3405,
        },
        {
          date: "2016-05-07",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 3405,
        },
        {
          date: "2016-05-07",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          value: 3405,
        },
      ],
      multipleSelection: [] // 存储被勾选的数据
    };
  },

  methods: {
    deleteSelected() {
      // 遍历被勾选的数据并删除
      this.multipleSelection.forEach(item => {
        const index = this.tableData.indexOf(item);
        if (index !== -1) {
          this.tableData.splice(index, 1);
        }
      });
      this.multipleSelection = []; // 清空勾选数据
    },
    // 点击表格的选择框
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    
    formatter(row, column) {
      return row.address;
    },
    handleEdit(index, row) {
    //   console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index,123);
    },
  },
};
</script>

<style lang="less" scoped>
.an {
  width: 100%;
  height: 40px;
  display: flex;
 justify-content: flex-end;
  align-items: center;
  margin-bottom: 10px;
  .ming {
    width: 150px;
    height: 100%;
    margin-right: 2vw;
    display: flex;
    align-items: center;
    button {
      width: 40%;
      height: 30px;
      margin-left: 10%;
      border-radius: 10px;
      color: #fff;
      border: none;
    }
  }
}
.el-table{
    width: 100%;
    height: 89%;
    overflow-y: auto;
}
.el-table::-webkit-scrollbar {
    display: none;
}

</style>
